define(['zepto', 'butterfly/view','../../bsl',
    'text!./runtime_launch.html'
], function($, View, bsl, runtime_launch) {
    var me = null;

    var view = View.extend({
        events: {

            // ！！！！ 由于 引入 touch.js 后，tap事件会变成双击，所以 本页面内不能使用tap，用click代替。
            "tap .openDoc" : "openDoc",
            "tap #back" : "back",

      
        },
        render: function() {
            me = this;
        },

        onShow: function() {

            // 绑定自定义事件 滑动切换日历等           


        },
                androidMarket:function ( pname ) {
            bsl.runtime.openURL( "market://details?id="+pname );
        },
        iosAppstore:function ( url ) {
            bsl.runtime.openURL( "itms-apps://"+url );
        },
        openBrowser:function () {
            var url = "http://www.dcloud.io/";
            bsl.runtime.openURL( url );
        },
        openMap:function () {
            var url = "";
            switch ( bsl.os.name ) {
                case "Android":
                url = "geo:39.96310,116.340698?q=%e6%95%b0%e5%ad%97%e5%a4%a9%e5%a0%82";
                break;
                case "iOS":
                url = "http://maps.apple.com/?q=%e6%95%b0%e5%ad%97%e5%a4%a9%e5%a0%82&ll=39.96310,116.340698&spn=0.008766,0.019441";
                break;
                default:
                return;
                break;
            }
            bsl.runtime.openURL( url, function( e ) {
                bsl.nativeUI.alert( "检查到您未安装地图程序\n" );
            } );
        },
        openBMap:function () {
            var url=null,id=null,f=null;
            switch ( bsl.os.name ) {
                case "Android":
                url = "bdapp://map/marker?coord_type=gcj02&location=39.96310,116.340698&title=数字天堂";
                //url = "intent://map/marker?coordtype=gcj02&location=39.96310,116.340698&title=数字天堂#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end";
                f = androidMarket;
                id = "com.baidu.BaiduMap";
                break;
                case "iOS":
                url = "baidumap://map/marker?coordtype=gcj02&location=39.96310,116.340698&title=数字天堂";
                f = iosAppstore;
                id = "itunes.apple.com/cn/app/bai-du-de-tu-yu-yin-dao-hang/id452186370?mt=8";
                break;
                default:
                return;
                break;
            }
            bsl.runtime.openURL( url, function(e) {
                bsl.nativeUI.confirm( "检查到您未安装\"百度地图\"，是否到商城搜索下载？", function(i){
                    if ( i.index == 0 ) {
                        f(id);
                    }
                } );
            } );
        },
        openAMap:function () {
            var url=null,id=null,f=null;
            switch ( bsl.os.name ) {
                case "Android":
                url = "androidamap://viewMap?poiname=数字天堂&lat=39.96310,116.340698&dev=0";
                f = androidMarket;
                id = "com.autonavi.minimap";
                break;
                case "iOS":
                url = "iosamap://navi?backScheme=helloh5&poiname=数字天堂&lat=39.96310&lon=116.340698&dev=1";
                f = iosAppstore;
                id = "itunes.apple.com/cn/app/gao-tu-zhuan-ye-dao-hang-ban/id461703208?mt=8";
                break;
                default:
                return;
                break;
            }
            bsl.runtime.openURL( url, function( e ) {
                bsl.nativeUI.confirm( "检查到您未安装\"高德地图\"，是否到商城搜索下载？", function(i){
                    if ( i.index == 0 ) {
                        f(id);
                    }
                } );
            }, id );
        },
        openMarket:function () {
            var url="";
            switch ( bsl.os.name ) {
                case "Android": {
                    //url = "market://details?id=com.dheaven.helloh5";
                    url = "market://details?id=io.dcloud.HelloH5";
                    //url = "market://search?q=HelloH5";
                    //url = "market://search?q=pub:HelloH5";
                }
                break;
                case "iOS": {
                    url = "itms-apps://itunes.apple.com/cn/app/hello-h5+/id682211190?l=zh&mt=8";
                }
                break;
            }
            bsl.runtime.openURL( url );
        },
        openWeixin:function () {
            if ( bsl.os.name == "Android" ) {
                bsl.runtime.launchApplication( {pname:"com.tencent.mm"}
                    , function ( e ) {
                        bsl.nativeUI.confirm( "检查到您未安装\"微信\"，是否到商城搜索下载？", function(i){
                            if ( i.index == 0 ) {
                                androidMarket( "com.tencent.mm" );
                            }
                        } );
                } );
            } else if ( bsl.os.name == "iOS" ) {
                bsl.runtime.launchApplication( {action:"weixin://RnUbAwvEilb1rU9g9yBU"}, function ( e ) {
                    bsl.nativeUI.confirm( "检查到您未安装\"微信\"，是否到商城搜索下载？", function(i){
                        if ( i.index == 0 ) {
                            iosAppstore( "itunes.apple.com/cn/app/wechat/id414478124?mt=8" );
                        }
                    } );
                } );
            }
        //  var url = "http://weixin.qq.com/r/RnUbAwvEilb1rU9g9yBU";
        //  bsl.runtime.openURL( url );
        },
        openWeibo:function () {
            if ( bsl.os.name == "Android" ) {
                bsl.runtime.launchApplication( {pname:"com.sina.weibo"}
                    , function ( e ) {
                        bsl.nativeUI.confirm( "检查到您未安装\"微博\"，是否到商城搜索下载？", function(i){
                            if ( i.index == 0 ) {
                                androidMarket( "com.sina.weibo" );
                            }
                        } );
                } );
            } else if ( bsl.os.name == "iOS" ) {
                bsl.runtime.launchApplication( {action:"sinaweibo://dhnetwork"}, function ( e ) {
                    bsl.nativeUI.confirm( "检查到您未安装\"微博\"，是否到商城搜索下载？", function(i){
                        if ( i.index == 0 ) {
                            iosAppstore( "itunes.apple.com/cn/app/wei-bo/id350962117?mt=8" );
                        }
                    } );
                } );
            }
        //  var url = "http://weibo.com/dhnetwork";
        //  bsl.runtime.openURL( url );
        },
          back : function(e){
            window.history.go(-1);
        },
        openDoc:function(){
             window.butterfly.navigate('/doc/events.html', {
                trigger: true
            });


        },
     
             
            });
    return view;
});
